<template>
	<view>
		<page-head :title="'企业账户'" :headtype="2"></page-head>
		<view class="nolist" v-if="datas.length <= 0">
			<image class="nolistimg" :src="apifun.serveimg +'qynone.png'" mode="widthFix"></image>
		</view>
		<view class="list">
			<view class="item marginAuto flex" v-for="(item,index) in datas">
				<view class="zbusi" v-if="item.pid == 0">
					<image src="@/static/icon/qylt.png" mode=""></image>
					<text class="zbusititle">主企业</text>
				</view>
				<view class="iteml" @click="apifun.navigate('/pages/usermy/businessxq','id='+item.id)">
					<view class="itemlname flex" style="width:100%;">
						<view class="ellipsis01" style="max-width:70%;">{{ item.company_name }}</view>
						<view class="itemlnamelab mainColor" v-if="item.company_type.includes('1')">工业</view>
						<view class="itemlnamelab mainColor" v-if="item.company_type.includes('2')">农业</view>
					</view>
					<view class="itemltime">添加时间：{{ item.create_time }}</view>
				</view>
				<view class="itemr">
					<view class="itemricon" @click="delqyfun(index)" v-if="usermsg.company_pid == 0 && item.pid  != 0">
						<uv-icon name="trash" size="22" color="#E51818"></uv-icon>
					</view>
					<view class="itemrbtn mainBg baiColor" v-if="item.status == 2 && usermsg.company_pid == 0 && item.pid  != 0" @click="apifun.navigate('/pages/usermy/businessxg','id='+item.id)">修改</view>
					<view class="itemrbtn mainColor" v-if="item.status == 1" style="background:#ECF7FF;">审核中</view>
					<view class="itemrbtn mainColor" v-if="item.status == 3 && item.pid  != 0" style="background:#ECF7FF;" @click="apifun.navigate('/pages/usermy/businessxg','id='+item.id)">已拒绝</view>
				</view>
			</view>
		</view>
		<view class="marginAuto" style="width:600rpx;margin-top:40rpx;" v-if="usermsg.company_pid == 0">
			<uv-button text="添加企业" @click="apifun.navigate('/pages/usermy/businessxg')" :customStyle="{
				'background':'#2340FF',
				'color':'#fff',
				'font-size':'30rpx',
				'width':'600rpx',
				'height':'100rpx',
				'border-radius':'20rpx',
				'marginTop':'100rpx'
			}"></uv-button>
		</view>
		<!-- 删除 -->
		<uv-popup ref="delpopup" mode="center" round="20">
			<view class="noticepup">
				<view class="noticepuptitle"><text class="noticepuptitlemsg">确定删除该企业账户信息吗？</text></view>
				<view class="boticebtn flex">
					<view class="boticebtneach closebtn" @click="closeqyfun">取消</view>
					<view class="boticebtneach mainBg baiColor" @click="delenterfun">确定</view>
				</view>
			</view>
		</uv-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				apifun:this.apifun,
				datas:[],
				delid:'',
				delindex:'',
				usermsg:{}
			};
		},
		onLoad() {
			this.companyList()
			this.usermsgfun()
		},
		onShow() {
			this.companyList()
		},
		methods: {
			companyList(){
				this.apifun.unirequest('/user/company/getCompanyList','post',{},(res)=>{
					if(res.code === 200){
						let datas = res.data;
						this.datas = datas;
					}else{
						this.apifun.toast(res.msg)
					}
				})
			},
			
			delenterfun(){  // 删除
				this.apifun.unirequest('/user/company/delCompanyInfo','post',{
					id:this.delid,
				},(res)=>{
					if(res.code === 200){
						let datas = res.data;
						this.datas.splice(this.delindex*1,1)
						this.$refs.delpopup.close()
					}else{
						this.apifun.toast(res.msg)
					}
				})
			},
			usermsgfun(){
				this.apifun.unirequest('/user/user/getUserInfo','post',{},(res)=>{
					if(res.code === 200){
						let datas = res.data;
						this.usermsg = datas;
						uni.setStorageSync('usermsg',datas);
					}else{
						this.apifun.toast(res.msg)
					}
				})
			},
			delqyfun(index){
				this.delid = this.datas[index].id;
				this.delindex = index;
				this.$refs.delpopup.open()
			},
			closeqyfun(){
				this.$refs.delpopup.close()
			}
		},
	};
</script>

<style scoped lang="scss">
	.nolistimg{
		display: block;
		margin: auto;
		margin-top: 200rpx;
		width: 600rpx;
	}
	.item{
		position: relative;
		width: 630rpx;
		padding: 50rpx 30rpx 28rpx;
		background:linear-gradient(to bottom, #F4FAFF,#ffffff);
		border-radius: 10rpx;
		margin-top: 20rpx;
		border:1px solid #EFF1F6;
		margin-top:70rpx;
		justify-content: space-between;
		.zbusi{
			position: absolute;
			z-index: 10;
			width: 160rpx;
			height: 90rpx;
			left: 0;
			top: -45rpx;
			image{
				position: absolute;
				width: 160rpx;
				height: 90rpx;
			}
			.zbusititle{
				position: absolute;
				z-index: 11;
				color: #fff;
				font-size:30rpx;
				width: 160rpx;
				line-height:54rpx;
				text-align: center;
			}
		}
		.iteml{
			width: 70%;
			.itemlname{
				font-size: 30rpx;
				color: #333333;
				font-weight: 600;
				margin-bottom:20rpx;
				.itemlnamelab{
					width: 100rpx;
					text-align: center;
					line-height: 40rpx;
					background-color:#E6E9FF;
					padding: 0 16rpx;
					margin-left: 20rpx;
					font-size:24rpx;
					border-radius: 10rpx;
				}
			}
			.itemltime{
				font-size: 24rpx;
				color: #999999;
				line-height: 50rpx;
			}
		}
		.itemr{
			.itemricon{
				width: 40rpx;
				margin: auto;
			}
			.itemrbtn{
				width: 150rpx;
				height: 70rpx;
				line-height: 70rpx;
				text-align: center;
				border-radius:10rpx;
				font-size:30rpx;
				margin-top: 20rpx;
			}
		}
	}
	// popup
	.noticepup{
		position: relative;
		width: 600rpx;
		border-radius:30rpx;
		.noticepuptitle{
			position: relative;
			width: 600rpx;
			height: 240rpx;
			font-weight: 600;
			background:linear-gradient(to bottom, #B0D9FF,#ffffff);
			.noticepuptitlemsg{
				position: absolute;
				top:120rpx;
				width: 600rpx;
				height: 70rpx;
				color:#333333;
				font-size: 34rpx;
				text-align: center;
			}
		}
		.boticebtn{
			margin-top:30rpx;
			color: #fff;
			font-size:30rpx;
			width: 600rpx;
			height:100rpx;
			line-height: 100rpx;
			text-align: center;
			.closebtn{
				color:#2340FF;
				background-color: #DBEEFF;
			}
			.boticebtneach{
				width: 50%;
			}
		}
	}
</style>